package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.Video;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 邵康
 * @date 2021/11/23 16:10
 */
@CrossOrigin
@RestController
@Api(tags = "视频")
@RequestMapping("/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation("添加视频,title可选默认文件名，urlFile,duration,父id必须,返回视频封面地址 对于番剧类型会触发动态更新")
    @PostMapping("/add")
    public R<List<String>> add(Video video) {
        return videoService.add(video);
    }

    @ApiOperation("deleteRes")
    @GetMapping("/delete")
    public R<Void> delete(Integer id) {
        return videoService.delete(id);
    }

    @ApiOperation("update")
    @PostMapping("/update")
    public R<Void> update(Video video) {
        return videoService.update(video);
    }

    @ApiOperation("page")
    @GetMapping("/page")
    public R<IPage<Video>> page(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer size) {
        return videoService.page(page, size);
    }

    @ApiOperation("获取单个视频 测试API")
    @GetMapping("/getVideo")
    public R<Video> getVideo(Integer id) {
        return videoService.getVideo(id);
    }

}
